package com.zzx.boot.utils;

import com.zzx.boot.constant.GlobalEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author tan
 * @version 1.0
 * @date 2023/7/7 15:02
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {

    private Integer code;
    private T data;
    private String msg;


    public static <T>R<T> success(T data){
        return new R<T>(200,data,"请求成功");
    }

    public static <T>R<T> success(T data,String msg){
        return new R<T>(200,data,msg);
    }


    public static R error(Integer code,String msg) {
        return new R(code,null,msg);
    }

    public static R error(GlobalEnum e) {
        return new R(e.getCode(),null,e.getMsg());
    }
}
